package chp07;

import java.util.Arrays;

public class Test13b {

    public static void main(String[] args) {
        //数组插入内容
        String[] names = {"jack","tom","mike","peter","jim",null};
        System.out.println(Arrays.toString(names));
        //插入的算法
        // 把 小明 插入到 tom 的前面
        // 插入前的内容:      [jack, tom, mike, peter, jim, null]
        // 插入后的预期内容:  [jack, 小明, tom, mike, peter, jim]
        //手动

//        names[5] = names[4];
//        names[4] = names[3];
//        names[3] = names[2];
//        names[2] = names[1];
        //自动版
        int index = 1; //假设已经知道需要插入的位置
        for (int i = names.length-1; i > index; i--){
            names[i] = names[i-1];
        }

        System.out.println(Arrays.toString(names));
        names[index] = "小明";
        System.out.println(Arrays.toString(names));
    }
}